package com.csoa.community.requests;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;

import android.content.Context;

import com.csoa.community.bean.OffDocComWordBean;
import com.csoa.community.net.ErrorMsg;
import com.csoa.community.utils.AndroidUtils;
import com.csoa.community.utils.Json;
import com.csoa.community.utils.StringUtils;

public class ComWordRequest extends AbstractRequest {

	public List<OffDocComWordBean> mComWords;
	private Context context;
	public ComWordRequest(Context context,List<BasicNameValuePair> requestValues) {
		super(OFFICIAL_DOC_COMMON_WORD_METHOD, requestValues);
		this.context = context;
	}
	
	public ComWordRequest() {
		
	}

	

	@Override
	protected void parseRemaingInfo(String json) throws ErrorMsg, JSONException {
		if(!StringUtils.isEmpty(json)) {
			if(json.equals("[]")) {
				mComWords = new ArrayList<OffDocComWordBean>();
				return;
			}
			String strJson = "{value:"+json +"}";
			AndroidUtils.setGlobal("ComWord", "strComWord", strJson, context);
			Json jsonAttachs = new Json(strJson);
			mComWords = new ArrayList<OffDocComWordBean>();
			fillAttachList(jsonAttachs,mComWords);
		}
		
	}
	
	
	public void fillAttachList(Json json, List<OffDocComWordBean> aComWords) {
		Json[] jsons = json.getJsonArray("value");
		
		for (int i=0;i<jsons.length;i++) {
			OffDocComWordBean offComWord = new OffDocComWordBean();
			offComWord.id = jsons[i].getString("id");
			offComWord.UserGUID = jsons[i].getString("UserGUID");
			offComWord.CommonWord = jsons[i].getString("CommonWord");
			offComWord.SortID = jsons[i].getString("SortID");
			aComWords.add(offComWord);
		}
		
	}
}
